//
//  MyAboutViewController.m
//  News
//
//  Created by weige on 16/6/6.
//  Copyright © 2016年 weige. All rights reserved.
//

#import "MyAboutViewController.h"
#import "MineHeaderView.h"
#import "SetingViewViewController.h"
#import "MineTabeHeadView.h"
#import "MineTableViewCell.h"

@interface MyAboutViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    MineHeaderView *headAndSettingView;
    MineTabeHeadView *tablehead;
    UIView *tableHeaderView;
    UITableView *myTableInfo;
}
@end

@implementation MyAboutViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
    //隐藏navback
     [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self lodataCellData];
    [self createHeaderAndSetting];
    [self bulidTableView];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(click:) name:@"clickmy" object:nil];
    myTableInfo=[[UITableView alloc]initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, SCREEN_HEIGHT-150-50) style:UITableViewStylePlain];
    [self buildTableMyUI];
    
    
}
//添加通知
-(void)click:(NSNotification *)sender
{
    MyOrderViewController *ordervc=[[MyOrderViewController alloc]init];

    int tap=[[sender.userInfo objectForKey:@"clicktap"] intValue];
    switch (tap) {
        case 0:
            [self.navigationController pushViewController:ordervc animated:YES];
            break;
        case 1:
            NSLog(@"2");
            break;
        case 2:
            NSLog(@"3");
            break;
        default:
            break;
    }

}
/*!
 *  @author weige, 16-06-14 15:06:59
 *
 *  @brief 替换导航栏为自定义的
 */
-(void)createHeaderAndSetting
{
    headAndSettingView=[[MineHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150)];
    
    self.view.backgroundColor=[UIColor lightGrayColor];
    [headAndSettingView.setBtn addTarget:self action:@selector(setclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:headAndSettingView];
    
}
/*!
 *  @author weige, 16-06-14 15:06:46
 *
 *  @brief 创建表头
 */
-(void)bulidTableView
{
    tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 150, SCREEN_WIDTH, 60)];
    tableHeaderView.backgroundColor=[UIColor lightGrayColor];
    [self.view addSubview:tableHeaderView];
    tablehead=[[MineTabeHeadView alloc]initWithFrame:CGRectMake(0, 0, tableHeaderView.frame.size.width, tableHeaderView.frame.size.height)];
    [tableHeaderView addSubview:tablehead];

}
-(void)buildTableMyUI
{
    myTableInfo.tableHeaderView=tableHeaderView;
    myTableInfo.dataSource=self;
    myTableInfo.delegate=self;
    [self.view addSubview:myTableInfo];
}
#pragma tableData tabledelegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        
        return 2;
    }
    else if (section==1)
    {
        return 1;
    }
    else
        
    {
        return 2;
    }
    //return [self lodataCellData].count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"mycell"];
    if (cell==nil) {
        
        cell=[[MineTableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:@"mycell"];
    }
    if (indexPath.section==0) {
        cell.mine=[self lodataCellData][indexPath.row];
    }
    else if (indexPath.section==1)
    {
        cell.mine=[self lodataCellData][2];
    }
    else
    {
        if (indexPath.row==0) {
            
            cell.mine=[self lodataCellData][3];
        }
        else
        {
            cell.mine=[self lodataCellData][4];
        }
    }
    //cell.mine=[self lodataCellData][indexPath.row];
    return cell;
}
/*!
 *  @author weige, 16-06-15 07:06:58
 *
 *  @brief 选中cell
 *
 *  @param tableView
 *  @param indexPath 
 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        
        if (indexPath.row==0) {
            
              NSLog(@"0-1");
        }
        else if (indexPath.row==1)
        {
            NSLog(@"0-2");
        }
      
    }
    else if (indexPath.section==1)
    {
        if (indexPath.row==0) {
            
            NSLog(@"1-1");
        }
    }
    else if (indexPath.section==2)
    {
        if (indexPath.row==0) {
            
            NSLog(@"2-1");
        }
        else if (indexPath.row==1)
        {
            NSLog(@"2-2");
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0;
}

-(NSArray *)lodataCellData
{
    NSString *path=[[NSBundle mainBundle]pathForResource:@"MinePlist.plist" ofType:nil];
    NSArray *arr=[[NSArray alloc]initWithContentsOfFile:path];
    NSLog(@"%@",arr);
    return arr;
}
/*!
 *  @author weige, 16-06-13 16:06:44
 *
 *  @brief 点击设置按钮
 *
 *  @param sender
 */
-(void)setclick:(UIButton *)sender
{
    SetingViewViewController *settView=[[SetingViewViewController alloc]init];
    
    [self.navigationController pushViewController:settView animated:YES];
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
